using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace WeberTimeTracker.Models.Mapping
{
    public class ProjectMap : EntityTypeConfiguration<Project>
    {
        public ProjectMap()
        {
            // Primary Key
            this.HasKey(t => t.Project_ID);

            // Properties
            this.Property(t => t.Project_Name)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Projects");
            this.Property(t => t.Project_ID).HasColumnName("Project_ID");
            this.Property(t => t.Client_ID).HasColumnName("Client_ID");
            this.Property(t => t.Rate_ID).HasColumnName("Rate_ID");
            this.Property(t => t.Project_Name).HasColumnName("Project_Name");

            // Relationships
            this.HasRequired(t => t.Client)
                .WithMany(t => t.Projects)
                .HasForeignKey(d => d.Client_ID);
            this.HasRequired(t => t.Rate)
                .WithMany(t => t.Projects)
                .HasForeignKey(d => d.Rate_ID);

        }
    }
}
